package actions;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.ReviewerModel;
import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;

public class ChairsHomeAction extends Action {
    // is there a way to make this global for the application
    public final int REVIEW_PROCESS_THRESHOLD = 3;

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws DbException {
        // gets number of reviewers
        int numReviewers = ReviewerModel.getNumReviewers();
        RowSet crsReviewers = ReviewerModel.fetchAllReviewer();
        String error = (String)request.getSession(false).getAttribute("reviewError");
        
        // replace this with request scope?
        request.setAttribute("numReviewers", numReviewers);
        request.setAttribute("crsReviewers", crsReviewers);
        request.setAttribute("reviewError", error);
                        
        // if there is enough reviewers then go to analytics
        if(ReviewerModel.reviewProcessHasBegun()){
            return mapping.findForward("processbegun");
        }else{
            // if has not begun set error message
            return mapping.findForward("processnotbegun");
        }
    }
}
